package com.miplus.ccrm.core.service.sto;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.core.controller.vo.sto.RsReturnCollectRecordReqVo;
import com.miplus.ccrm.core.controller.vo.sto.RsReturnCollectRecordResVo;
import com.miplus.ccrm.core.pojo.PlRsReturnCollectRecord;
import com.miplus.ccrm.core.mapper.PlRsReturnCollectRecordMapper;
import com.miplus.ccrm.core.pojo.PlRsReturnSoundRecord;
import org.springframework.stereotype.Service;

/**
 * @author Yaohui
 * @description 针对表【pl_rs_return_collect_record】的数据库操作Service实现
 * @createDate 2025-06-09 14:42:08
 */
@Service
public class PlRsReturnCollectRecordServiceImpl extends MPJBaseServiceImpl<PlRsReturnCollectRecordMapper, PlRsReturnCollectRecord>
        implements PlRsReturnCollectRecordService{

    @Override
    public IPage<RsReturnCollectRecordResVo> rsCollectRecordPage(RsReturnCollectRecordReqVo reqVo) {
        return selectJoinListPage(new Page<>(reqVo.getPageNum(),reqVo.getPageSize()),RsReturnCollectRecordResVo.class,
                new MPJLambdaWrapper<>(PlRsReturnCollectRecord.class)
                        .leftJoin(PlRsReturnSoundRecord.class,PlRsReturnSoundRecord::getActionId,PlRsReturnCollectRecord::getActionId)
                        .selectAll(PlRsReturnCollectRecord.class)
                        .selectAs(PlRsReturnSoundRecord::getFileStatus,RsReturnCollectRecordResVo::getFileStatus)
                        .selectAs("'电催'",RsReturnCollectRecordResVo::getActionType)
                        .eq(PlRsReturnCollectRecord::getCustId,reqVo.getCustId())
                        .orderBy(JPubUtils.IsNotEmpty(reqVo.getColumn()),reqVo.getIsASC(),getColumn(reqVo.getColumn()))

        );


    }

    private String getColumn(String column){
        if(JPubUtils.IsEmpty(column)) {
            return column;
        }
        switch (column){
            case "rsCreateTime":
                column="t.rs_create_time";
                break;
        }
        return column;
    }
}